package TCPDemo;

import java.io.*;
import java.net.InetSocketAddress;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) {
        Socket socket = new Socket();
        try {
            socket.connect(new InetSocketAddress( 8888));
            socket.setSoTimeout(5000);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
            objectOutputStream.writeUTF("I am client");
            objectOutputStream.flush();
            String s = objectInputStream.readUTF();
            System.out.println(s);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }finally {
            try {
                socket.close();
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }

        }
    }
}
